#include "stm32f10x.h"                  // Device header
#include "OLED.h"
#include "LED.h"
#include "Encoder.h"
#include "Delay.h"
#include "Timer.h"

int16_t Speed;

int main(void)
{
	OLED_Init();
	LED_Init();
	Encoder_Init();
	Timer_Init();
	OLED_ShowString(1,1,"Speed:");
	while(1)
	{
		OLED_ShowSignedNum(1, 7, Speed, 5);
//		OLED_ShowSignedNum(1, 7, Encoder_GetCNT(), 5);
//		Delay_ms(1000);
	}
}

void TIM2_IRQHandler(void)
{
	if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)		//判断是否是TIM2的更新事件触发的中断
	{
		Speed = Encoder_GetCNT();								//每隔固定时间段读取一次编码器计数增量值，即为速度值
		TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
	}
}
